#!/bin/sh

rm -rf ../.env.pro

# 是否使用IPV6
echo "是否支持要IPV6: 请输入[1|0]"
read enable_v6

echo "是否使用桥接服务: 请输入[1|0]"
read is_bridge

appkey=$(echo -n "$(date +%s)" | md5sum | awk '{print $1}')

envStr="APP_ENV=pro
APP_DEBUG=0
APP_KEY=${appkey}
STATIC_ACCESS=1
"

echo "微信机器人推送地址: 请输入"
read webhool_url

envStr="${envStr}\nWEBHOOK_WECHAT=\"${webhool_url}\"\n"

if [ "$is_bridge" = "1" ]; then

    envStr="${envStr}\n#桥接配置\n"
    if [ "$enable_v6" = "1" ]; then
        envStr="${envStr}BRIDGE_TYPE=3\n"
    else
        envStr="${envStr}BRIDGE_TYPE=1\n"
    fi

    echo "请输入桥接服务地址: "
    read bridge_host
    envStr="${envStr}BRIDGE_HOST=${bridge_host}\n"


    echo "请输入桥接名称: "
    read bridge_name
    envStr="${envStr}BRIDGE_NAME=${bridge_name}\n"

    echo "请输入桥接认证token: "
    read bridge_token
    envStr="${envStr}BRIDGE_TOKEN=${bridge_token}\n"
fi

envStr="${envStr}\n#server配置
SERV_MODE=2
ADMIN_PORT=7201
RPC_PORT=7202
HTTP_PORT=7203
MQTT_PORT=7210
PROXY_PORT=7280
SOCKS5_PORT=7281
"

if [ "$enable_v6" = "1" ]; then
    envStr="${envStr}SERV_HOST=::\n"
    envStr="${envStr}SOCK_TCP_TYPE=3\n"
    envStr="${envStr}SOCK_UDP_TYPE=4\n"

    envStr="${envStr}\n#代理配置\n"
    envStr="${envStr}PROXY_ENABLE_IPV6=1\n"
else
    envStr="${envStr}SERV_HOST=0.0.0.0\n"
    envStr="${envStr}SOCK_TCP_TYPE=1\n"
    envStr="${envStr}SOCK_UDP_TYPE=2\n"

    envStr="${envStr}\n#代理配置\n"
    envStr="${envStr}PROXY_ENABLE_IPV6=0\n"
fi

envStr="${envStr}PROXY_ENABLE_AUTH=1\n"

echo "$envStr" >> ../.env.pro


docker-compose up -d